import { Model } from "sequelize";
import UserModel from "../models/UserModel";

export default class UserDao {
  static async login(account: string, password: string) {
    let result = await UserModel.findOne({
      attributes: { exclude: ["password"] },
      where: {
        account,
        password
      }
    })

    if (result) {
      result = result.toJSON()
    } else {
      // 没有找到时
      result = ({} as Model<any, any>)
    }

    return result

  }

  static async create(data: any) {
    const result = await UserModel.create(data)
    return result.toJSON()
  }

  static async getUserCount() {
    const result = await UserModel.count()
    return result
  }
}